fixes for action=render on image pages
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 /**
3 * @package MediaWiki
4 */
5
6 /**
7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
8 */
9 if( defined( 'MEDIAWIKI' ) ) {
10
11 # See design.txt
12
13 if($wgUseTeX) require_once( 'Math.php' );
14
15 /**
16 * @todo document
17 * @package MediaWiki
18 */
19 class OutputPage {
20 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
21 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
22 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
23 var $mSubtitle, $mRedirect;
24 var $mLastModified, $mETag, $mCategoryLinks;
25 var $mScripts, $mLinkColours;
26
27 var $mSuppressQuickbar;
28 var $mOnloadHandler;
29 var $mDoNothing;
30 var $mContainsOldMagic, $mContainsNewMagic;
31 var $mIsArticleRelated;
32 var $mParserOptions;
33 var $mShowFeedLinks = false;
34 var $mEnableClientCache = true;
35 var $mArticleBodyOnly = false;
36
37 /**
38 * Constructor
39 * Initialise private variables
40 */
41 function OutputPage() {
42 $this->mHeaders = $this->mCookies = $this->mMetatags =
43 $this->mKeywords = $this->mLinktags = array();
44 $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
45 $this->mRedirect = $this->mLastModified =
46 $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
47 $this->mOnloadHandler = '';
48 $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
49 $this->mSuppressQuickbar = $this->mPrintable = false;
50 $this->mLanguageLinks = array();
51 $this->mCategoryLinks = array() ;
52 $this->mDoNothing = false;
53 $this->mContainsOldMagic = $this->mContainsNewMagic = 0;
54 $this->mParserOptions = ParserOptions::newFromUser( $temp = NULL );
55 $this->mSquidMaxage = 0;
56 $this->mScripts = '';
57 $this->mETag = false;
58 }
59
60 function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ) ; }
61 function addCookie( $name, $val ) { array_push( $this->mCookies, array( $name, $val ) ); }
62 function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; }
63
64 # To add an http-equiv meta tag, precede the name with "http:"
65 function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
66 function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
67 function addScript( $script ) { $this->mScripts .= $script; }
68 function getScript() { return $this->mScripts; }
69
70 function setETag($tag) { $this->mETag = $tag; }
71 function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
72 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly; }
73
74 function addLink( $linkarr ) {
75 # $linkarr should be an associative array of attributes. We'll escape on output.
76 array_push( $this->mLinktags, $linkarr );
77 }
78
79 function addMetadataLink( $linkarr ) {
80 # note: buggy CC software only reads first "meta" link
81 static $haveMeta = false;
82 $linkarr['rel'] = ($haveMeta) ? 'alternate meta' : 'meta';
83 $this->addLink( $linkarr );
84 $haveMeta = true;
85 }
86
87 /**
88 * checkLastModified tells the client to use the client-cached page if
89 * possible. If sucessful, the OutputPage is disabled so that
90 * any future call to OutputPage->output() have no effect. The method
91 * returns true iff cache-ok headers was sent.
92 */
93 function checkLastModified ( $timestamp ) {
94 global $wgLang, $wgCachePages, $wgUser;
95 if ( !$timestamp || $timestamp == '19700101000000' ) {
96 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
97 return;
98 }
99 if( !$wgCachePages ) {
100 wfDebug( "CACHE DISABLED\n", false );
101 return;
102 }
103 if( $wgUser->getOption( 'nocache' ) ) {
104 wfDebug( "USER DISABLED CACHE\n", false );
105 return;
106 }
107
108 $timestamp=wfTimestamp(TS_MW,$timestamp);
109 $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched ) );
110
111 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
112 # IE sends sizes after the date like this:
113 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
114 # this breaks strtotime().
115 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
116 $ismodsince = wfTimestamp( TS_MW, strtotime( $modsince ) );
117 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
118 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
119 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
120 # Make sure you're in a place you can leave when you call us!
121 header( "HTTP/1.0 304 Not Modified" );
122 $this->mLastModified = $lastmod;
123 $this->sendCacheControl();
124 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
125 $this->disable();
126 return true;
127 } else {
128 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
129 $this->mLastModified = $lastmod;
130 }
131 } else {
132 wfDebug( "client did not send If-Modified-Since header\n", false );
133 $this->mLastModified = $lastmod;
134 }
135 }
136
137 function getPageTitleActionText () {
138 global $action;
139 switch($action) {
140 case 'edit':
141 return wfMsg('edit');
142 case 'history':
143 return wfMsg('history_short');
144 case 'protect':
145 return wfMsg('protect');
146 case 'unprotect':
147 return wfMsg('unprotect');
148 case 'delete':
149 return wfMsg('delete');
150 case 'watch':
151 return wfMsg('watch');
152 case 'unwatch':
153 return wfMsg('unwatch');
154 case 'submit':
155 return wfMsg('preview');
156 case 'info':
157 return wfMsg('info_short');
158 default:
159 return '';
160 }
161 }
162
163 function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
164 function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
165 function setPageTitle( $name ) {
166 global $action, $wgContLang;
167 $name = $wgContLang->convert($name, true);
168 $this->mPagetitle = $name;
169 if(!empty($action)) {
170 $taction = $this->getPageTitleActionText();
171 if( !empty( $taction ) ) {
172 $name .= ' - '.$taction;
173 }
174 }
175 $this->setHTMLTitle( $name . ' - ' . wfMsg( 'wikititlesuffix' ) );
176 }
177 function getHTMLTitle() { return $this->mHTMLtitle; }
178 function getPageTitle() { return $this->mPagetitle; }
179 function setSubtitle( $str ) { $this->mSubtitle = /*$this->parse(*/$str/*)*/; } // @bug 2514
180 function getSubtitle() { return $this->mSubtitle; }
181 function isArticle() { return $this->mIsarticle; }
182 function setPrintable() { $this->mPrintable = true; }
183 function isPrintable() { return $this->mPrintable; }
184 function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
185 function isSyndicated() { return $this->mShowFeedLinks; }
186 function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
187 function getOnloadHandler() { return $this->mOnloadHandler; }
188 function disable() { $this->mDoNothing = true; }
189
190 function setArticleRelated( $v ) {
191 $this->mIsArticleRelated = $v;
192 if ( !$v ) {
193 $this->mIsarticle = false;
194 }
195 }
196 function setArticleFlag( $v ) {
197 $this->mIsarticle = $v;
198 if ( $v ) {
199 $this->mIsArticleRelated = $v;
200 }
201 }
202
203 function isArticleRelated() { return $this->mIsArticleRelated; }
204
205 function getLanguageLinks() { return $this->mLanguageLinks; }
206 function addLanguageLinks($newLinkArray) {
207 $this->mLanguageLinks += $newLinkArray;
208 }
209 function setLanguageLinks($newLinkArray) {
210 $this->mLanguageLinks = $newLinkArray;
211 }
212
213 function getCategoryLinks() {
214 return $this->mCategoryLinks;
215 }
216 function addCategoryLinks($newLinkArray) {
217 $this->mCategoryLinks += $newLinkArray;
218 }
219 function setCategoryLinks($newLinkArray) {
220 $this->mCategoryLinks += $newLinkArray;
221 }
222
223 function suppressQuickbar() { $this->mSuppressQuickbar = true; }
224 function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
225
226 function addHTML( $text ) { $this->mBodytext .= $text; }
227 function clearHTML() { $this->mBodytext = ''; }
228 function getHTML() { return $this->mBodytext; }
229 function debug( $text ) { $this->mDebugtext .= $text; }
230
231 function setParserOptions( $options ) {
232 return wfSetVar( $this->mParserOptions, $options );
233 }
234
235 /**
236 * Convert wikitext to HTML and add it to the buffer
237 * Default assumes that the current page title will
238 * be used.
239 */
240 function addWikiText( $text, $linestart = true ) {
241 global $wgTitle;
242 $this->addWikiTextTitle($text, $wgTitle, $linestart);
243 }
244
245 function addWikiTextWithTitle($text, &$title, $linestart = true) {
246 $this->addWikiTextTitle($text, $title, $linestart);
247 }
248
249 function addWikiTextTitle($text, &$title, $linestart) {
250 global $wgParser, $wgUseTidy;
251 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions, $linestart );
252 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
253 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
254 if ( $parserOutput->getCacheTime() == -1 ) {
255 $this->enableClientCache( false );
256 }
257 $this->addHTML( $parserOutput->getText() );
258 }
259
260 /**
261 * Add wikitext to the buffer, assuming that this is the primary text for a page view
262 * Saves the text into the parser cache if possible
263 */
264 function addPrimaryWikiText( $text, $cacheArticle ) {
265 global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
266
267 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, true );
268
269 $text = $parserOutput->getText();
270
271 if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) {
272 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
273 }
274
275 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
276 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
277 if ( $parserOutput->getCacheTime() == -1 ) {
278 $this->enableClientCache( false );
279 }
280 $this->addHTML( $text );
281 }
282
283 /**
284 * Add the output of a QuickTemplate to the output buffer
285 * @param QuickTemplate $template
286 */
287 function addTemplate( &$template ) {
288 ob_start();
289 $template->execute();
290 $this->addHtml( ob_get_contents() );
291 ob_end_clean();
292 }
293
294 /**
295 * Parse wikitext and return the HTML. This is for special pages that add the text later
296 */
297 function parse( $text, $linestart = true ) {
298 global $wgParser, $wgTitle;
299 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
300 return $parserOutput->getText();
301 }
302
303 /**
304 * @param $article
305 * @param $user
306 *
307 * @return bool
308 */
309 function tryParserCache( $article, $user ) {
310 global $wgParserCache;
311 $parserOutput = $wgParserCache->get( $article, $user );
312 if ( $parserOutput !== false ) {
313 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
314 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
315 $this->addHTML( $parserOutput->getText() );
316 $t = $parserOutput->getTitleText();
317 if( !empty( $t ) ) {
318 $this->setPageTitle( $t );
319 }
320 return true;
321 } else {
322 return false;
323 }
324 }
325
326 /**
327 * Set the maximum cache time on the Squid in seconds
328 * @param $maxage
329 */
330 function setSquidMaxage( $maxage ) {
331 $this->mSquidMaxage = $maxage;
332 }
333
334 /**
335 * Use enableClientCache(false) to force it to send nocache headers
336 * @param $state
337 */
338 function enableClientCache( $state ) {
339 return wfSetVar( $this->mEnableClientCache, $state );
340 }
341
342 function sendCacheControl() {
343 global $wgUseSquid, $wgUseESI;
344
345 if ($this->mETag)
346 header("ETag: $this->mETag");
347
348 # don't serve compressed data to clients who can't handle it
349 # maintain different caches for logged-in users and non-logged in ones
350 header( 'Vary: Accept-Encoding, Cookie' );
351 if( $this->mEnableClientCache ) {
352 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
353 ! $this->isPrintable() && $this->mSquidMaxage != 0 )
354 {
355 if ( $wgUseESI ) {
356 # We'll purge the proxy cache explicitly, but require end user agents
357 # to revalidate against the proxy on each visit.
358 # Surrogate-Control controls our Squid, Cache-Control downstream caches
359 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
360 # start with a shorter timeout for initial testing
361 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
362 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
363 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
364 } else {
365 # We'll purge the proxy cache for anons explicitly, but require end user agents
366 # to revalidate against the proxy on each visit.
367 # IMPORTANT! The Squid needs to replace the Cache-Control header with
368 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
369 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
370 # start with a shorter timeout for initial testing
371 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
372 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
373 }
374 } else {
375 # We do want clients to cache if they can, but they *must* check for updates
376 # on revisiting the page.
377 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
378 header( "Expires: -1" );
379 header( "Cache-Control: private, must-revalidate, max-age=0" );
380 }
381 if($this->mLastModified) header( "Last-modified: {$this->mLastModified}" );
382 } else {
383 wfDebug( "** no caching **\n", false );
384
385 # In general, the absence of a last modified header should be enough to prevent
386 # the client from using its cache. We send a few other things just to make sure.
387 header( 'Expires: -1' );
388 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
389 header( 'Pragma: no-cache' );
390 }
391 }
392
393 /**
394 * Finally, all the text has been munged and accumulated into
395 * the object, let's actually output it:
396 */
397 function output() {
398 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
399 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
400 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
401
402 if( $this->mDoNothing ){
403 return;
404 }
405 $fname = 'OutputPage::output';
406 wfProfileIn( $fname );
407 $sk = $wgUser->getSkin();
408
409 if ( '' != $this->mRedirect ) {
410 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
411 # Standards require redirect URLs to be absolute
412 global $wgServer;
413 $this->mRedirect = $wgServer . $this->mRedirect;
414 }
415 if( $this->mRedirectCode == '301') {
416 if( !$wgDebugRedirects ) {
417 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
418 }
419 $this->mLastModified = wfTimestamp( TS_RFC2822 );
420 }
421
422 $this->sendCacheControl();
423
424 if( $wgDebugRedirects ) {
425 $url = htmlspecialchars( $this->mRedirect );
426 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
427 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
428 print "</body>\n</html>\n";
429 } else {
430 header( 'Location: '.$this->mRedirect );
431 }
432 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
433 return;
434 }
435
436
437 # Buffer output; final headers may depend on later processing
438 ob_start();
439
440 $this->transformBuffer();
441
442 # Disable temporary placeholders, so that the skin produces HTML
443 $sk->postParseLinkColour( false );
444
445 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
446 header( 'Content-language: '.$wgContLanguageCode );
447
448 $exp = time() + $wgCookieExpiration;
449 foreach( $this->mCookies as $name => $val ) {
450 setcookie( $name, $val, $exp, '/' );
451 }
452
453 if ($this->mArticleBodyOnly) {
454 $this->out($this->mBodytext);
455 } else {
456 wfProfileIn( 'Output-skin' );
457 $sk->outputPage( $this );
458 wfProfileOut( 'Output-skin' );
459 }
460
461 $this->sendCacheControl();
462 ob_end_flush();
463 }
464
465 function out( $ins ) {
466 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
467 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
468 $outs = $ins;
469 } else {
470 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
471 if ( false === $outs ) { $outs = $ins; }
472 }
473 print $outs;
474 }
475
476 function setEncodings() {
477 global $wgInputEncoding, $wgOutputEncoding;
478 global $wgUser, $wgContLang;
479
480 $wgInputEncoding = strtolower( $wgInputEncoding );
481
482 if( $wgUser->getOption( 'altencoding' ) ) {
483 $wgContLang->setAltEncoding();
484 return;
485 }
486
487 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
488 $wgOutputEncoding = strtolower( $wgOutputEncoding );
489 return;
490 }
491 $wgOutputEncoding = $wgInputEncoding;
492 }
493
494 /**
495 * Returns a HTML comment with the elapsed time since request.
496 * This method has no side effects.
497 * @return string
498 */
499 function reportTime() {
500 global $wgRequestTime;
501
502 $now = wfTime();
503 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
504 $start = (float)$sec + (float)$usec;
505 $elapsed = $now - $start;
506
507 # Use real server name if available, so we know which machine
508 # in a server farm generated the current page.
509 if ( function_exists( 'posix_uname' ) ) {
510 $uname = @posix_uname();
511 } else {
512 $uname = false;
513 }
514 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
515 $hostname = $uname['nodename'];
516 } else {
517 # This may be a virtual server.
518 $hostname = $_SERVER['SERVER_NAME'];
519 }
520 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
521 $hostname, $elapsed );
522 return $com;
523 }
524
525 /**
526 * Note: these arguments are keys into wfMsg(), not text!
527 */
528 function errorpage( $title, $msg ) {
529 global $wgTitle;
530
531 $this->mDebugtext .= 'Original title: ' .
532 $wgTitle->getPrefixedText() . "\n";
533 $this->setPageTitle( wfMsg( $title ) );
534 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
535 $this->setRobotpolicy( 'noindex,nofollow' );
536 $this->setArticleRelated( false );
537 $this->enableClientCache( false );
538 $this->mRedirect = '';
539
540 $this->mBodytext = '';
541 $this->addWikiText( wfMsg( $msg ) );
542 $this->returnToMain( false );
543
544 $this->output();
545 wfErrorExit();
546 }
547
548 /**
549 * Display an error page indicating that a given version of MediaWiki is
550 * required to use it
551 *
552 * @param mixed $version The version of MediaWiki needed to use the page
553 */
554 function versionRequired( $version ) {
555 global $wgUser;
556
557 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
558 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
559 $this->setRobotpolicy( 'noindex,nofollow' );
560 $this->setArticleRelated( false );
561 $this->mBodytext = '';
562
563 $sk = $wgUser->getSkin();
564 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
565 $this->returnToMain();
566 }
567
568 /**
569 * Display an error page noting that a given permission bit is required.
570 * This should generally replace the sysopRequired, developerRequired etc.
571 * @param string $permission key required
572 */
573 function permissionRequired( $permission ) {
574 global $wgUser;
575
576 $this->setPageTitle( wfMsg( 'badaccess' ) );
577 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
578 $this->setRobotpolicy( 'noindex,nofollow' );
579 $this->setArticleRelated( false );
580 $this->mBodytext = '';
581
582 $sk = $wgUser->getSkin();
583 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
584 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
585 $this->returnToMain();
586 }
587
588 /**
589 * @deprecated
590 */
591 function sysopRequired() {
592 global $wgUser;
593
594 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
595 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
596 $this->setRobotpolicy( 'noindex,nofollow' );
597 $this->setArticleRelated( false );
598 $this->mBodytext = '';
599
600 $sk = $wgUser->getSkin();
601 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
602 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
603 $this->returnToMain();
604 }
605
606 /**
607 * @deprecated
608 */
609 function developerRequired() {
610 global $wgUser;
611
612 $this->setPageTitle( wfMsg( 'developertitle' ) );
613 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
614 $this->setRobotpolicy( 'noindex,nofollow' );
615 $this->setArticleRelated( false );
616 $this->mBodytext = '';
617
618 $sk = $wgUser->getSkin();
619 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
620 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
621 $this->returnToMain();
622 }
623
624 function loginToUse() {
625 global $wgUser, $wgTitle, $wgContLang;
626
627 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
628 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
629 $this->setRobotpolicy( 'noindex,nofollow' );
630 $this->setArticleFlag( false );
631 $this->mBodytext = '';
632 $this->addWikiText( wfMsg( 'loginreqtext' ) );
633
634 # We put a comment in the .html file so a Sysop can diagnose the page the
635 # user can't see.
636 $this->addHTML( "\n<!--" .
637 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
638 ':' .
639 $wgTitle->getDBkey() . '-->' );
640 $this->returnToMain(); # Flip back to the main page after 10 seconds.
641 }
642
643 function databaseError( $fname, $sql, $error, $errno ) {
644 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
645
646 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
647 $this->setRobotpolicy( 'noindex,nofollow' );
648 $this->setArticleRelated( false );
649 $this->enableClientCache( false );
650 $this->mRedirect = '';
651
652 if( !$wgShowSQLErrors ) {
653 $sql = wfMsg( 'sqlhidden' );
654 }
655
656 if ( $wgCommandLineMode ) {
657 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
658 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
659 } else {
660 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
661 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
662 }
663
664 if ( $wgCommandLineMode || !is_object( $wgUser )) {
665 print $msg."\n";
666 wfErrorExit();
667 }
668 $this->mBodytext = $msg;
669 $this->output();
670 wfErrorExit();
671 }
672
673 function readOnlyPage( $source = null, $protected = false ) {
674 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
675
676 $this->setRobotpolicy( 'noindex,nofollow' );
677 $this->setArticleRelated( false );
678
679 if( $protected ) {
680 $this->setPageTitle( wfMsg( 'viewsource' ) );
681 $this->addWikiText( wfMsg( 'protectedtext' ) );
682 } else {
683 $this->setPageTitle( wfMsg( 'readonly' ) );
684 if ( $wgReadOnly ) {
685 $reason = $wgReadOnly;
686 } else {
687 $reason = file_get_contents( $wgReadOnlyFile );
688 }
689 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
690 }
691
692 if( is_string( $source ) ) {
693 if( strcmp( $source, '' ) == 0 ) {
694 $source = wfMsg( 'noarticletext' );
695 }
696 $rows = $wgUser->getOption( 'rows' );
697 $cols = $wgUser->getOption( 'cols' );
698 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
699 htmlspecialchars( $source ) . "\n</textarea>";
700 $this->addHTML( $text );
701 }
702
703 $this->returnToMain( false );
704 }
705
706 function fatalError( $message ) {
707 $this->setPageTitle( wfMsg( "internalerror" ) );
708 $this->setRobotpolicy( "noindex,nofollow" );
709 $this->setArticleRelated( false );
710 $this->enableClientCache( false );
711 $this->mRedirect = '';
712
713 $this->mBodytext = $message;
714 $this->output();
715 wfErrorExit();
716 }
717
718 function unexpectedValueError( $name, $val ) {
719 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
720 }
721
722 function fileCopyError( $old, $new ) {
723 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
724 }
725
726 function fileRenameError( $old, $new ) {
727 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
728 }
729
730 function fileDeleteError( $name ) {
731 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
732 }
733
734 function fileNotFoundError( $name ) {
735 $this->fatalError( wfMsg( 'filenotfound', $name ) );
736 }
737
738 /**
739 * return from error messages or notes
740 * @param $auto automatically redirect the user after 10 seconds
741 * @param $returnto page title to return to. Default is Main Page.
742 */
743 function returnToMain( $auto = true, $returnto = NULL ) {
744 global $wgUser, $wgOut, $wgRequest;
745
746 if ( $returnto == NULL ) {
747 $returnto = $wgRequest->getText( 'returnto' );
748 }
749 $returnto = htmlspecialchars( $returnto );
750
751 $sk = $wgUser->getSkin();
752 if ( '' == $returnto ) {
753 $returnto = wfMsgForContent( 'mainpage' );
754 }
755 $link = $sk->makeKnownLink( $returnto, '' );
756
757 $r = wfMsg( 'returnto', $link );
758 if ( $auto ) {
759 $titleObj = Title::newFromText( $returnto );
760 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
761 }
762 $wgOut->addHTML( "\n<p>$r</p>\n" );
763 }
764
765 /**
766 * This function takes the existing and broken links for the page
767 * and uses the first 10 of them for META keywords
768 */
769 function addMetaTags () {
770 global $wgLinkCache , $wgOut ;
771 $good = array_keys ( $wgLinkCache->mGoodLinks ) ;
772 $bad = array_keys ( $wgLinkCache->mBadLinks ) ;
773 $a = array_merge ( $good , $bad ) ;
774 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
775 $a = implode ( ',' , $a ) ;
776 $strip = array(
777 "/<.*?>/" => '',
778 "/_/" => ' '
779 );
780 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
781
782 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
783 }
784
785 /**
786 * @private
787 * @return string
788 */
789 function headElement() {
790 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
791 global $wgUser, $wgContLang, $wgRequest;
792
793 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
794 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
795 } else {
796 $ret = '';
797 }
798
799 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
800
801 if ( "" == $this->mHTMLtitle ) {
802 $this->mHTMLtitle = wfMsg( "pagetitle", $this->mPagetitle );
803 }
804
805 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
806 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
807 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle ) . "</title>\n";
808 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
809
810 $ret .= $this->getHeadLinks();
811 global $wgStylePath;
812 if( $this->isPrintable() ) {
813 $media = '';
814 } else {
815 $media = "media='print'";
816 }
817 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
818 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
819
820 $sk = $wgUser->getSkin();
821 $ret .= $sk->getHeadScripts();
822 $ret .= $this->mScripts;
823 $ret .= $sk->getUserStyles();
824
825 $ret .= "</head>\n";
826 return $ret;
827 }
828
829 function getHeadLinks() {
830 global $wgRequest, $wgStylePath;
831 $ret = '';
832 foreach ( $this->mMetatags as $tag ) {
833 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
834 $a = 'http-equiv';
835 $tag[0] = substr( $tag[0], 5 );
836 } else {
837 $a = 'name';
838 }
839 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
840 }
841 $p = $this->mRobotpolicy;
842 if ( '' == $p ) { $p = 'index,follow'; }
843 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
844
845 if ( count( $this->mKeywords ) > 0 ) {
846 $strip = array(
847 "/<.*?>/" => '',
848 "/_/" => ' '
849 );
850 $ret .= "<meta name=\"keywords\" content=\"" .
851 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
852 }
853 foreach ( $this->mLinktags as $tag ) {
854 $ret .= '<link';
855 foreach( $tag as $attr => $val ) {
856 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
857 }
858 $ret .= " />\n";
859 }
860 if( $this->isSyndicated() ) {
861 # FIXME: centralize the mime-type and name information in Feed.php
862 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
863 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
864 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
865 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
866 }
867
868 return $ret;
869 }
870
871 /**
872 * Run any necessary pre-output transformations on the buffer text
873 */
874 function transformBuffer( $options = 0 ) {
875 }
876
877
878 /**
879 * Turn off regular page output and return an error reponse
880 * for when rate limiting has triggered.
881 * @todo: i18n
882 * @access public
883 */
884 function rateLimited() {
885 global $wgOut;
886 $wgOut->disable();
887 wfHttpError( 500, 'Internal Server Error',
888 'Sorry, the server has encountered an internal error. ' .
889 'Please wait a moment and hit "refresh" to submit the request again.' );
890 }
891
892 }
893
894 } // MediaWiki
895
896 ?>